import request from '@/utils/request'

// ==================== 聊天室管理 ====================

// 分页查询聊天室
export function getChatRoomPage(params) {
  return request({
    url: '/v1/chat/group/page',
    method: 'get',
    params
  })
}

// 获取聊天室列表（别名）
export function getChatRooms(params) {
  return getChatRoomPage(params)
}

// 获取聊天室详情
export function getChatRoomDetail(id) {
  return request({
    url: `/v1/chat/group/${id}`,
    method: 'get'
  })
}

// 创建聊天室
export function createChatRoom(data) {
  return request({
    url: '/v1/chat/group',
    method: 'post',
    data
  })
}

// 更新聊天室
export function updateChatRoom(id, data) {
  return request({
    url: `/v1/chat/group/${id}`,
    method: 'put',
    data
  })
}

// 删除聊天室
export function deleteChatRoom(id) {
  return request({
    url: `/v1/chat/group/${id}`,
    method: 'delete'
  })
}

// 启用/禁用聊天室
export function toggleChatRoomStatus(id, enabled) {
  return request({
    url: `/v1/chat/group/${id}/toggle`,
    method: 'post',
    params: { enabled }
  })
}

// 更新聊天室状态
export function updateChatRoomStatus(id, status) {
  return request({
    url: `/v1/chat/group/${id}/status`,
    method: 'put',
    params: { status }
  })
}

// 获取聊天室统计
export function getChatRoomStatistics(id) {
  return request({
    url: `/v1/chat-rooms/${id}/statistics`,
    method: 'get'
  })
}

// ==================== 消息管理 ====================

// 分页查询消息
export function getMessagePage(params) {
  return request({
    url: '/v1/messages',
    method: 'get',
    params
  })
}

// 获取消息详情
export function getMessageDetail(id) {
  return request({
    url: `/v1/messages/${id}`,
    method: 'get'
  })
}

// 删除消息
export function deleteMessage(id) {
  return request({
    url: `/v1/messages/${id}`,
    method: 'delete'
  })
}

// 批量删除消息
export function deleteBatchMessage(ids) {
  return request({
    url: '/v1/messages/batch',
    method: 'delete',
    data: ids
  })
}

// 撤回消息
export function recallMessage(id) {
  return request({
    url: `/v1/messages/${id}/recall`,
    method: 'post'
  })
}

// 审核消息
export function reviewMessage(id, approved, reason) {
  return request({
    url: `/v1/messages/${id}/review`,
    method: 'post',
    params: { approved, reason }
  })
}

// 获取聊天室消息
export function getChatRoomMessages(roomId, params) {
  return request({
    url: `/v1/messages/room/${roomId}`,
    method: 'get',
    params
  })
}

// 获取用户消息
export function getUserMessages(userId, params) {
  return request({
    url: `/v1/messages/user/${userId}`,
    method: 'get',
    params
  })
}

// 搜索消息
export function searchMessages(keyword, params) {
  return request({
    url: '/v1/messages/search',
    method: 'get',
    params: { keyword, ...params }
  })
}

// 导出消息记录
export function exportMessages(params) {
  return request({
    url: '/v1/messages/export',
    method: 'get',
    params,
    responseType: 'blob'
  })
}

// ==================== 用户管理 ====================

// 分页查询聊天用户
export function getChatUserPage(params) {
  return request({
    url: '/v1/chat-users',
    method: 'get',
    params
  })
}

// 获取用户详情
export function getChatUserDetail(id) {
  return request({
    url: `/v1/chat-users/${id}`,
    method: 'get'
  })
}

// 禁言用户
export function muteUser(userId, roomId, duration, reason) {
  return request({
    url: `/v1/chat-users/${userId}/mute`,
    method: 'post',
    params: { roomId, duration, reason }
  })
}

// 解除禁言
export function unmuteUser(userId, roomId) {
  return request({
    url: `/v1/chat-users/${userId}/unmute`,
    method: 'post',
    params: { roomId }
  })
}

// 踢出用户
export function kickUser(userId, roomId, reason) {
  return request({
    url: `/v1/chat-users/${userId}/kick`,
    method: 'post',
    params: { roomId, reason }
  })
}

// 拉黑用户
export function blockUser(userId, reason) {
  return request({
    url: `/v1/chat-users/${userId}/block`,
    method: 'post',
    params: { reason }
  })
}

// 解除拉黑
export function unblockUser(userId) {
  return request({
    url: `/v1/chat-users/${userId}/unblock`,
    method: 'post'
  })
}

// 获取在线用户
export function getOnlineUsers(roomId) {
  return request({
    url: '/v1/chat-users/online',
    method: 'get',
    params: { roomId }
  })
}

// 获取用户聊天统计
export function getUserChatStatistics(userId) {
  return request({
    url: `/v1/chat-users/${userId}/statistics`,
    method: 'get'
  })
}

// ==================== 敏感词管理 ====================

// 分页查询敏感词
export function getSensitiveWordPage(params) {
  return request({
    url: '/v1/sensitive-words',
    method: 'get',
    params
  })
}

// 创建敏感词
export function createSensitiveWord(data) {
  return request({
    url: '/v1/sensitive-words',
    method: 'post',
    data
  })
}

// 更新敏感词
export function updateSensitiveWord(id, data) {
  return request({
    url: `/v1/sensitive-words/${id}`,
    method: 'put',
    data
  })
}

// 删除敏感词
export function deleteSensitiveWord(id) {
  return request({
    url: `/v1/sensitive-words/${id}`,
    method: 'delete'
  })
}

// 批量导入敏感词
export function importSensitiveWords(data) {
  return request({
    url: '/v1/sensitive-words/import',
    method: 'post',
    data
  })
}

// 导出敏感词
export function exportSensitiveWords() {
  return request({
    url: '/v1/sensitive-words/export',
    method: 'get',
    responseType: 'blob'
  })
}

// 刷新敏感词缓存
export function refreshSensitiveWordCache() {
  return request({
    url: '/v1/sensitive-words/refresh-cache',
    method: 'post'
  })
}
